package com.oceansoft.mobile.econsole.modules.api.service.impl;

import com.oceansoft.mobile.econsole.cache.redis.CacheBaseService;
import com.oceansoft.mobile.econsole.common.constant.Constant;
import com.oceansoft.mobile.econsole.common.util.HttpClientUtil;
import com.oceansoft.mobile.econsole.modules.api.entity.SubNews;
import com.oceansoft.mobile.econsole.modules.api.service.ISubService;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.jlapi.entity.AppMessage;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * ClassName: SubServiceImpl
 * Desc:
 * Date： 2016/10/27
 * Created：shaom
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SubServiceImpl extends CacheBaseService implements ISubService {

    private static final Logger logger = Logger.getLogger(SubServiceImpl.class);

    @Override
    public Result saveCode(String code) {
        return null;
    }

    @Override
    public Result subNews(SubNews news) {
        logger.info(news.toString());
        AppMessage appMessage = new AppMessage();
        appMessage.setReceiver(Constant.SUB_NEWS_TAG);//与前端商定
        appMessage.setMsgType(AppMessage.MessageType.NEWS_SUB);
        appMessage.setTitle(news.getTitle());
        appMessage.setContent(news.getTitle());
        appMessage.setUrl(news.getUrl());
        HttpClientUtil.doPostString(configInfo.getAppSendUrl(), appMessage);
//        String s = HttpClientUtil.doPostString("http://172.17.118.29:8081/web/api/v1/msg/app/", appMessage);
        return new Result(Result.SUCC);
    }
}
